home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / termv4.6 / extras / source / gtlayout-source.lha / LTP_PrintBoxLine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  3.4 KB  |  204 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14.  
  15. /*****************************************************************************/
  16.  
  17.  
  18. BOOL
  19. LTP_PrintLinePadded(LayoutHandle *Handle,LONG Left,LONG Top,LONG Space,STRPTR Line,LONG Len)
  20. {
  21.     struct RastPort    *RPort    = &Handle->RPort;
  22.     LONG             Size    = 0;
  23.     LONG             Start    = 0;
  24.     LONG             Count    = 0;
  25.     LONG             i        = 0;
  26.     LONG             Width    = 0;
  27.  
  28.     while(i < Len && Line[i] == ' ')
  29.     {
  30.         Size++;
  31.         i++;
  32.     }
  33.  
  34.     while(i < Len)
  35.     {
  36.         while(i < Len && Line[i] != ' ')
  37.         {
  38.             Size++;
  39.             i++;
  40.         }
  41.  
  42.         Width += TextLength(RPort,&Line[Start],Size);
  43.  
  44.         Count++;
  45.  
  46.         while(i < Len && Line[i] == ' ')
  47.             i++;
  48.  
  49.         Start    = i;
  50.         Size    = 0;
  51.     }
  52.  
  53.     if(Width)
  54.     {
  55.         LONG j,TextLeft;
  56.  
  57.         Space -= Width;
  58.  
  59.         j = Start = Size = 0;
  60.  
  61.         while(j < Len && Line[j] == ' ')
  62.         {
  63.             Size++;
  64.             j++;
  65.         }
  66.  
  67.         LTP_SetAPen(RPort,Handle->TextPen);
  68.  
  69.         TextLeft = Left;
  70.  
  71.         Count--;
  72.  
  73.         for(i = 0 ; i <= Count ; i++)
  74.         {
  75.             if(i)
  76.             {
  77.                 LONG Delta;
  78.  
  79.                 if(Delta = (Space * i) / Count - (Space * (i - 1)) / Count)
  80.                 {
  81.                     LTP_SetAPen(RPort,Handle->BackgroundPen);
  82.                     LTP_FillBox(RPort,TextLeft,Top,Delta,Handle->GlyphHeight);
  83.                     LTP_SetAPen(RPort,Handle->TextPen);
  84.  
  85.                     TextLeft += Delta;
  86.                 }
  87.             }
  88.  
  89.             while(j < Len && Line[j] != ' ')
  90.             {
  91.                 Size++;
  92.                 j++;
  93.             }
  94.  
  95.             LTP_PrintText(RPort,&Line[Start],Size,TextLeft,Top);
  96.  
  97.             TextLeft += TextLength(RPort,&Line[Start],Size);
  98.  
  99.             while(j < Len && Line[j] == ' ')
  100.                 j++;
  101.  
  102.             Start = j;
  103.             Size = 0;
  104.         }
  105.  
  106.         return(TRUE);
  107.     }
  108.     else
  109.         return(FALSE);
  110. }
  111.  
  112.  
  113. /*****************************************************************************/
  114.  
  115.  
  116. VOID
  117. LTP_PrintLine(LayoutHandle *handle,LONG alignType,LONG left,LONG top,LONG space,STRPTR line,LONG len)
  118. {
  119.     struct RastPort *rp;
  120.  
  121.     rp = &handle->RPort;
  122.  
  123.     LTP_SetPens(rp,handle->BackgroundPen,handle->BackgroundPen,JAM2);
  124.  
  125.     if(alignType == ALIGNTEXT_PAD)
  126.     {
  127.         if(LTP_PrintLinePadded(handle,left,top,space,line,len))
  128.             return;
  129.     }
  130.     else
  131.     {
  132.         LONG                 width;
  133.         struct TextExtent     extent;
  134.  
  135.         len        = TextFit(rp,line,len,&extent,NULL,1,space,32767);
  136.         width    = extent.te_Width;
  137.  
  138.         if(len)
  139.         {
  140.             LONG textLeft;
  141.  
  142.             switch(alignType)
  143.             {
  144.                 case ALIGNTEXT_LEFT:
  145.  
  146.                     textLeft = left;
  147.  
  148.                     if(width < space)
  149.                         LTP_FillBox(rp,left + width,top,space - width,handle->GlyphHeight);
  150.  
  151.                     break;
  152.  
  153.                 case ALIGNTEXT_CENTERED:
  154.  
  155.                     textLeft = left + (space - width) / 2;
  156.  
  157.                     if(width < space)
  158.                     {
  159.                         LONG fill;
  160.  
  161.                         if((fill = (space - width) / 2) > 0)
  162.                             LTP_FillBox(rp,left,top,fill,handle->GlyphHeight);
  163.                         else
  164.                             fill = 0;
  165.  
  166.                         fill += width;
  167.  
  168.                         if(fill < space)
  169.                             LTP_FillBox(rp,left + fill,top,space - fill,handle->GlyphHeight);
  170.                     }
  171.  
  172.                     break;
  173.  
  174.                 case ALIGNTEXT_RIGHT:
  175.  
  176.                     textLeft = left + space - width;
  177.  
  178.                     if(width < space)
  179.                         LTP_FillBox(rp,left,top,width,handle->GlyphHeight);
  180.  
  181.                     break;
  182.             }
  183.  
  184.             LTP_SetAPen(rp,handle->TextPen);
  185.             LTP_PrintText(rp,line,len,textLeft,top);
  186.  
  187.             return;
  188.         }
  189.     }
  190.  
  191.     LTP_FillBox(rp,left,top,space,handle->GlyphHeight);
  192. }
  193.  
  194.  
  195. /*****************************************************************************/
  196.  
  197.  
  198. VOID
  199. LTP_PrintBoxLine(LayoutHandle *handle,ObjectNode *node,LONG index)
  200. {
  201.     if(node->Special.Box.Lines && node->Special.Box.Lines[index])
  202.         LTP_PrintLine(handle,node->Special.Box.AlignText,node->Left + 4,node->Top + 2 + index * handle->GlyphHeight,node->Width - 8,node->Special.Box.Lines[index],strlen(node->Special.Box.Lines[index]));
  203. }
  204.